package dev.ece.suit.ui.shader;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Map;

import org.lwjgl.opengl.GL20;

import dev.ece.core.shader.DefaultTextureShader;

public class VariableWidthTextureShader extends DefaultTextureShader {

	private static VariableWidthTextureShader defaultVariableWidthTextureShader;
	
	public static VariableWidthTextureShader getDefaultVariableWidthTextureShader() throws FileNotFoundException {
		if(defaultVariableWidthTextureShader == null) {
			defaultVariableWidthTextureShader = new VariableWidthTextureShader(
					VariableWidthTextureShader.class.getClassLoader().getResourceAsStream("shaders/ui/variablewidth.vert"), 
					VariableWidthTextureShader.class.getClassLoader().getResourceAsStream("shaders/ui/default.frag")
					);
		}
		return defaultVariableWidthTextureShader;
	}
	
	private int offsetHandler;
	
	public VariableWidthTextureShader(InputStream vertexShaderInputStream, InputStream pixelShaderInputStream,
			Map<String, String> functions) {
		super(vertexShaderInputStream, pixelShaderInputStream, functions);
	}

	public VariableWidthTextureShader(InputStream vertexShaderInputStream, InputStream pixelShaderInputStream) {
		super(vertexShaderInputStream, pixelShaderInputStream);
	}

	public VariableWidthTextureShader(String vertexShaderSource, String pixelShaderSource) {
		super(vertexShaderSource, pixelShaderSource);
	}

	public VariableWidthTextureShader(StringBuffer vertexShaderSource, StringBuffer pixelShaderSource,
			Map<String, String> functions) {
		super(vertexShaderSource, pixelShaderSource, functions);
	}

	@Override
	protected void onInitializeHandler(int program) {
		super.onInitializeHandler(program);
		offsetHandler = GL20.glGetUniformLocation(program, "offset");
		
	}

	public void glOffset(float offset) {
		GL20.glUniform1f(offsetHandler, offset);
	}
	
	@Override
	public void clearup() {
		GL20.glDeleteShader(offsetHandler);
		super.clearup();
	}

}
